package  com.easidea.tim.flex
{
	import com.easidea.tim.flex.event.CustomerEvent;
	import com.easidea.tim.flex.util.ModelLocator;
	
	import mx.collections.ArrayCollection;
	import mx.collections.IViewCursor;


	public class Env
	{

		private static var modelLocator:ModelLocator=ModelLocator.getInstance();


		public static function dispatchEvent(evt:CustomerEvent):Boolean
		{
			return modelLocator.dispatchEvent(evt);
		}
		public static function addEventListener(type:String,listeners:Function):void {
			modelLocator.addEventListener(type,listeners);
		}
		
		public static function removeEventListener(type:String,listeners:Function):void {
			modelLocator.removeEventListener(type,listeners);
		}		
		
		public static function registerListeners(arrayCollection:ArrayCollection):void
		{
			var cursor:IViewCursor=arrayCollection.createCursor();
			while (!cursor.afterLast)
			{
				modelLocator.addEventListener(cursor.current.event, cursor.current.method);
				cursor.moveNext();
			}
		}
		public static function removeListeners(arrayCollection:ArrayCollection):void {
			 var cursor:IViewCursor = arrayCollection.createCursor();
			 while (!cursor.afterLast){
				 modelLocator.removeEventListener(cursor.current.event,cursor.current.method);
				 cursor.moveNext();
			 }
		}
		public static function removeListener(listenerName:String,arrayCollection:ArrayCollection):void {
			 var cursor:IViewCursor = arrayCollection.createCursor();
			 while (!cursor.afterLast){
			 	if(listenerName == cursor.current.event) {
			 	 trace(cursor.current.event);
			 	 modelLocator.removeEventListener(cursor.current.event,cursor.current.method);
			 	 break;
			 	}
				 cursor.moveNext();
			 }
		}		
	}
}